import { request } from "vendor/utils/T";
import { toApi } from "@/service/proxyApi";
import { RequestDataType, RespDataType } from "./apiType";

export * from "./apiType";

const { get, postJSON, del, put } = request;

/**
 * 获取字典数据分页列表
 */
export const getDictDataPageList = (params: { page: number, pageSize: number, dictType: string, dictLabel?: string, status?: number }) => {
  return get<RespDataType.DictDataPageList>(toApi("api/v1/system/dict/data/list"), params);
}

/**
 * 创建字典数据
 */
export const createDictData = (params: RequestDataType.CreateDictDataItem) => {
  return postJSON(toApi("api/v1/system/dict/data/add"), params);
}

/**
 * 获取字典数据信息
 */
export const getDictDataInfo = (dictCode: number) => {
  return get<RespDataType.DictDataInfoResp>(toApi("api/v1/system/dict/data/get"), { dictCode });
}

/**
 * 更新字典数据信息
 */
export const updateDictData = (dictCode: number, params: Partial<RequestDataType.UpdateDictDataItem>) => {
  return put(toApi(`api/v1/system/dict/data/edit`), { dictCode, ...params });
}

/**
 * 删除字典数据信息
 */
export const deleteDictData = (dictCodes: number[]) => {
  return del(toApi(`api/v1/system/dict/data/delete`), { ids: dictCodes });
}

